/*
 * ButtonDelegate.cpp  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "ButtonDelegate.h"

// ButtonDelegate :: Protected Constructor. ------------------------------------

/*!
 * \brief Constructs new ButtonDelegate object.
 *
 * \param env the JNIEnv pointer
 * \param obj the Button java object
 */
ButtonDelegate::ButtonDelegate(JNIEnv *env, jobject obj)
  : AbstractButtonDelegate(env, obj, new QPushButton())
{
  // empty constructor body
}

// ButtonDelegate :: Native Calls. ---------------------------------------------

/*!
 * \brief Returns button's default status.
 *
 * \return button's default status.
 */
jboolean ButtonDelegate::isDefault(JNIEnv *env)
{
  Q_UNUSED(env);
  return qPushButton()->isDefault();
}

/*!
 * \brief Sets button's default status.
 *
 * \param env the JNIEnv pointer
 * \param defaultCapable \c true if default
 */
void ButtonDelegate::setDefaultCapable(JNIEnv *env, jboolean defaultCapable)
{
  Q_UNUSED(env);
  qPushButton()->setDefault(defaultCapable);
}

/*!
 * \brief Sets button's auto default status.
 *
 * \param env the JNIEnv pointer
 * \param autoDefault \c true if auto default
 */
void ButtonDelegate::setAutoDefault(JNIEnv *env, jboolean autoDefault)
{
  Q_UNUSED(env);
  qPushButton()->setAutoDefault(autoDefault);
}

/*!
 * \brief Returns new instance of the delegate object.
 *
 * \param env the JNIEnv pointer 
 * \param obj the Button java object
 * 
 * \return new instance of the delegate object
 */
jlong ButtonDelegate::newInstance(JNIEnv *env, jobject obj)
{
  if (JNISwingWrapper::isSwingThread(env)) {
    return reinterpret_cast<jlong>(new ButtonDelegate(env, obj));
  }
  return SwingUtilitiesDelegate::invokeLongAndWait(env, obj, createMID());
}
